//
//  MOSelectedMessageAndTelView.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/20.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOSelectedMessageAndTelView.h"

@interface MOSelectedMessageAndTelView()

@property(nonatomic,strong)UIImageView *backImageView;

@end

@implementation MOSelectedMessageAndTelView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.01];
        self.alpha = 1;
        
        [self creatViewAndFrame:frame];
    }
    return self;
}

-(void)creatViewAndFrame:(CGRect)frame
{
    UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    [backButton addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:backButton];
    
    self.backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWConversions(170), kWConversions(170)*(129.0/338.0))];
    self.backImageView.centerX = 100 + kWConversions(16) + [NSString labelAutoCalculateRectWith:@"99999999999" WithFont:FONT_SIZE(15) MaxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)].width/2;
    self.backImageView.image = IMAGE(@"person_callSelected");
    self.backImageView.userInteractionEnabled = YES;
    [backButton addSubview:self.backImageView];
    
    NSArray *arr = @[@"打电话",@"发短信"];
    CGFloat buttonW = (self.backImageView.width - 1 - 10)/2;
    for (int i = 0; i<2; i++) {
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake((buttonW+1)*i + 5, 0, buttonW, self.backImageView.height)];
        button.titleLabel.font = FONT_SIZE(14);
        button.tag = i;
        [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:arr[i] forState:UIControlStateNormal];
        [self.backImageView addSubview:button];
        
        if (i==0) {
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(button.right, 0, 1, kWConversions(19))];
            line.backgroundColor = [UIColor whiteColor];
            line.centerY = button.centerY;
            [self.backImageView addSubview:line];
        }
    }
}

-(void)clickButton:(UIButton *)sender
{
    [self cancel];
    if (self.clickTelOrMessageButtonBlock) {
        self.clickTelOrMessageButtonBlock(sender.tag+1);
    }
}

-(void)cancel
{
    self.alpha = 0;
}


-(void)setContentMaxY:(CGFloat)contentMaxY
{
    self.backImageView.y = contentMaxY;
}
























@end
